<template>
  <div class="login-container">
    <div class="login-form">
      <div class="title">
        病理教学系统V2.0
      </div>
      <div class="ckt-input">
        <span class="svg-container">
          <svg-icon icon-class="user" />
        </span>
        <input v-model="loginForm.userName" type="text" placeholder="账号" />
      </div>

      <div class="ckt-input">
        <span class="svg-container">
          <svg-icon icon-class="password" />
        </span>
        <input
          v-model="loginForm.password"
          :type="showPsd ? 'text' : 'password'"
          placeholder="密码"
        />
        <span class="svg-container eye" @click="showPsd = !showPsd">
          <svg-icon :icon-class="showPsd ? 'eye-open' : 'eye'" />
        </span>
      </div>

      <el-button type="primary" style="width: 100%;" @click="handleLogin">
        登录
      </el-button>
    </div>
  </div>
</template>

<script>
  export default {
    name: 'Login',
    data() {
      return {
        loginForm: {
          userName: '',
          password: ''
        },
        showPsd: false
      }
    },
    created() {
      this.$store.dispatch('app/toggleHidden', true)
    },
    methods: {
      async handleLogin() {
        if (!this.loginForm.userName) {
          this.$Msg.error('请输入账号')
          return
        }
        if (!this.loginForm.password) {
          this.$Msg.error('请输入密码')
          return
        }

        const isLogin = await this.$store.dispatch('user/login', this.loginForm)
        if (isLogin) {
          this.$router.push('/')
        }
      }
    }
  }
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
  .login-container {
    position: fixed;
    height: 100%;
    width: 100%;
    background: url('~@/assets/login_bg.jpg') no-repeat 100% 100%;
    cursor: default;
    display: flex;
    justify-content: center;
    align-items: center;
    .login-form {
      width: 520px;
      max-width: 100%;
      position: relative;
      margin: 0 auto;
      margin-top: -10%;
      padding: 45px 35px;
      background-color: #fff;
      border-radius: 5px;
    }
    .title {
      font-size: 26px;
      font-weight: 400;
      color: #398de0;
      margin-bottom: 40px;
      text-align: center;
      font-weight: bold;
    }
    .ckt-input {
      margin-bottom: 20px;
      width: 100%;
      height: 40px;
      vertical-align: middle;
      position: relative;
      input {
        border: none;
        outline-style: none;
        font-size: 14px;
        font-family: 'Microsoft soft';
        box-sizing: border-box;
        height: 100%;
        width: 100%;
        padding: 0 40px;
        border: 1px solid #d8d7d7;
        border-radius: 5px;
        &:-webkit-autofill {
          -webkit-box-shadow: 0 0 0px 1000px #fff inset !important;
        }
        &:focus {
          border-color: #91b9df;
        }
      }
    }
    .svg-container {
      position: absolute;
      top: 12px;
      left: 12px;
    }
    .eye {
      left: auto;
      right: 15px;
      cursor: pointer;
    }
  }
</style>
